/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package movie.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import movie.utility.Constants;
import org.hibernate.validator.constraints.NotEmpty;
import rm.validator.password.Password;

/**
 *
 * @author admin
 */
@Entity
@Table(name = "user_access")
@NamedQueries({
    @NamedQuery(name = "UserAccess.findAll", query = "SELECT u FROM UserAccess u"),
    @NamedQuery(name = "UserAccess.findByUsernameNotDeleted", query = "SELECT u FROM UserAccess u WHERE u.userName = :userName AND  u.dateDeleted is NULL"),
    @NamedQuery(name = "UserAccess.findAllNotDeleted", query = "SELECT u FROM UserAccess u WHERE u.dateDeleted is NULL")})
public class UserAccess implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id_user_access")
    private Integer idUserAccess;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 20)
    @Column(name = "first_name")
    private String firstName;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 40)
    @Column(name = "last_name")
    private String lastName;
    @Basic(optional = false)
    @NotNull
    @Size(min = 13, max = 13, message = "JMBG must have 13 numbers")
    @Column(name = "jmbg")
    private String jmbg;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 30)
    @Column(name = "user_name")
    private String userName;
    @Basic(optional = false)
    @NotNull
//    @Password
    @Size(min = 1, max = 32)
    @Column(name = "password")
    private String password;
    @Basic(optional = false)
    @NotNull
    @Column(name = "active")
    private boolean active;
    @Basic(optional = false)
    @NotNull
    @Column(name = "user_type")
    private boolean userType;
    @Basic(optional = false)
    @NotNull
    @Column(name = "date_created")
    @Temporal(TemporalType.TIMESTAMP)
    private Date dateCreated;
    @Column(name = "date_deleted")
    @Temporal(TemporalType.TIMESTAMP)
    private Date dateDeleted;
    @ManyToMany(mappedBy = "userWatchedList", fetch = FetchType.LAZY)
    private List<Film> watchedFilmList;
    @ManyToMany(mappedBy = "userWishList", fetch = FetchType.LAZY)
    private List<Film> wishFilmList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idUserAccess", fetch = FetchType.LAZY)
    private List<Rating> ratingList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idUserAccess", fetch = FetchType.LAZY)
    private List<Comment> commentList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idUserAccess", fetch = FetchType.LAZY)
    private List<Favourite> favouriteList;
    @Transient
    private String transPassword;
    @Transient
    private String transPasswordNew1;
    @Transient
    private String transPasswordNew2;

    public UserAccess() {
    }

    public UserAccess(Integer idUserAccess) {
        this.idUserAccess = idUserAccess;
    }

    public UserAccess(Integer idUserAccess, String firstName, String lastName, String jmbg, String userName, String password, boolean active, boolean userType, Date dateCreated) {
        this.idUserAccess = idUserAccess;
        this.firstName = firstName;
        this.lastName = lastName;
        this.jmbg = jmbg;
        this.userName = userName;
        this.password = password;
        this.active = active;
        this.userType = userType;
        this.dateCreated = dateCreated;
    }

    public Integer getIdUserAccess() {
        return idUserAccess;
    }

    public void setIdUserAccess(Integer idUserAccess) {
        this.idUserAccess = idUserAccess;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getJmbg() {
        return jmbg;
    }

    public void setJmbg(String jmbg) {
        this.jmbg = jmbg;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public boolean getActive() {
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

    public boolean getUserType() {
        return userType;
    }

    public void setUserType(boolean userType) {
        this.userType = userType;
    }

    public Date getDateCreated() {
        return dateCreated;
    }

    public void setDateCreated(Date dateCreated) {
        this.dateCreated = dateCreated;
    }

    public List<Film> getWatchedFilmList() {
        return watchedFilmList;
    }

    public void setWatchedFilmList(List<Film> watchedFilmList) {
        this.watchedFilmList = watchedFilmList;
    }

    public List<Film> getWishFilmList() {
        return wishFilmList;
    }

    public void setWishFilmList(List<Film> wishFilmList) {
        this.wishFilmList = wishFilmList;
    }

    public List<Rating> getRatingList() {
        return ratingList;
    }

    public void setRatingList(List<Rating> ratingList) {
        this.ratingList = ratingList;
    }

    public List<Comment> getCommentList() {
        return commentList;
    }

    public void setCommentList(List<Comment> commentList) {
        this.commentList = commentList;
    }

    public List<Favourite> getFavouriteList() {
        return favouriteList;
    }

    public void setFavouriteList(List<Favourite> favouriteList) {
        this.favouriteList = favouriteList;
    }

    public Date getDateDeleted() {
        return dateDeleted;
    }

    public void setDateDeleted(Date dateDeleted) {
        this.dateDeleted = dateDeleted;
    }

    public String getTransFullName() {
        return firstName + " " + lastName;
    }

    public String getTransPassword() {
        return transPassword;
    }

    public void setTransPassword(String transPassword) {
        this.transPassword = transPassword;
    }

    public String getTransPasswordNew1() {
        return transPasswordNew1;
    }

    public void setTransPasswordNew1(String transPasswordNew1) {
        this.transPasswordNew1 = transPasswordNew1;
    }

    public String getTransPasswordNew2() {
        return transPasswordNew2;
    }

    public void setTransPasswordNew2(String transPasswordNew2) {
        this.transPasswordNew2 = transPasswordNew2;
    }

    public String getTransActiveIcon() {
        return active == true ? Constants.ICON_ACTIVE : Constants.ICON_UNACTIVE;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idUserAccess != null ? idUserAccess.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof UserAccess)) {
            return false;
        }
        UserAccess other = (UserAccess) object;
        if ((this.idUserAccess == null && other.idUserAccess != null) || (this.idUserAccess != null && !this.idUserAccess.equals(other.idUserAccess))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "movie.entity.UserAccess[ idUserAccess=" + idUserAccess + " ]";
    }
}
